/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chatUniversal;

import chatClient.GUI.Chatroom;
import chatServer.ChatServiceRemoteInterface;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author loki
 */
public class Notifier extends UnicastRemoteObject implements InterfNotifier {
    private Chatroom room;
    //private ChatServiceRemoteInterface service;
    
    //private String client;
    
    public Notifier(Chatroom room) throws RemoteException {
        this.room = room;
    }
    
    @Override
    public String getClient() throws RemoteException {
        return room.clientName.getText();
    }
    
    @Override
    public void retrieveMessages() throws RemoteException {
        List<Message> messages = room.service.getLatest(room.clientName.getText());
        
        Iterator iter = messages.iterator();
        for(int x = 0; x < messages.size(); x++) {
            Message message = (Message)iter.next();
            room.messagePrinter.append(message.fromClient + ": " + message.message + "\n");
        }
    }
}
